package com.idroc.coelacanth.service.servant;

import org.jboss.netty.buffer.ChannelBuffer;

import com.idroc.coelacanth.core.membership.Endpoint;
import com.idroc.coelacanth.core.message.AbstractMessage;

/**
 * 存储服侍器集合请求消息
 * @author yuyoo (yuyoo4j@163.com)
 * @date 2009-12-16 下午05:34:17
 */
public class ServantSetRequestMessage extends AbstractMessage {
	
	private Endpoint from = null; 

	@Override
	public void decode(ChannelBuffer ib) { 
		
		from = new Endpoint();
		from.setHost(decodeString(ib));
		from.setPort(ib.readInt());
	}

	@Override
	public void encode(ChannelBuffer ob) {

		encodeString(ob, from.getHost());
		ob.writeInt(from.getPort());
	}
	
	public Endpoint getFrom() {
		return from;
	}

	public void setFrom(Endpoint from) {
		this.from = from;
	}

	@Override
	public String toString() { 

		StringBuilder sb = new StringBuilder();
		sb.append("ServantSetRequestMessage[");
		sb.append("from:").append(from);
		sb.append("]");
		return sb.toString();
	}
}
